// takeEvery 接收action, put触发action
import { takeEvery, put } from 'redux-saga/effects'
import { register, register_success, register_fail } from '../actions/register'
import { API } from '../../config'
import axios from 'axios'


function* handleRegister (action) {
	try{
		yield axios.post(`${API}/signup`, action.payload)
		yield put(register_success())
	}catch (err) {
		yield put(register_fail({ message: err.response.data.error}))
	}
}


export default function* registerSaga () {
	// register 状态接收从组建传递过来的信息
	yield takeEvery(register, handleRegister)
}